let cate = require('../model/cate')
let {
    Router
} = require("express");
let router = new Router();
let lists = require('../static/cate.js')
Promise.all(lists().map(item => cate.create(item))).then((res) => {
    // console.log(res);
}).catch(error => console.log(error))

router.post('/select', async (req, res) => {
    // let {cate} = req.body;
    let datas = await cate.find();
    console.log(datas);
    res.status(200).json({
        msg: '查询成功',
        datas
    })
})

//挂号减一
router.post('/reduce', async (req, res) => {
    let {
        id,
        value
    } = req.body;
    console.log(id, value);
    let datas = await cate.findOneAndUpdate({
        _id: id
    }, {
        num: value
    });
    res.status(200).json({
        msg: '删除成功',
        datas
    })
})
module.exports = router;